<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>V8垃圾回收</title>
</head>
<body>
	<script type="text/javascript">
		const os = require("os");

		function getMemery(){
			let memory = process.memoryUsage();
			let format = function(bytes){
				return `${(bytes / 1024 / 1024).toFixed(2)}MB`;
			}

			let totalM = os.totalmem;
			let freeM = os.freemem;
			console.log(`totalM:${totalM}\tfreeM:${freeM}`);
			console.log(`heapTotal:${format(memory.heapTotal)}\theapUsed:${format(memory.heapUsed)}`);
		}

		let count = 0;
		let useMem = () => {
			let size = 20 * 1024 * 1024;
			let arr = new Array(size);
			console.log(count ++);
			return arr;
		}

		let total = [];
		for(let i = 0; i < 10; i ++){
			getMemery();
			total.push(useMem())
		}

		console.log("success");
	</script>
</body>
</html>